﻿<form method="post" id="form1">
    @Html.AntiForgeryToken()
    <div class="querybar">
        <table cellpadding="0" cellspacing="1" border="0" width="100%">
            <tr>
                <td>
                    应用名称：<input type="text" class="mytext" id="Name" name="Name" value="" style="width:250px" />
                    <input type="button" name="Search" onclick="query();" value="&nbsp;&nbsp;查&nbsp;询&nbsp;&nbsp;" class="mybutton" />
                    <input type="button" onclick="edit(''); return false;" value="&nbsp;&nbsp;添&nbsp;加&nbsp;&nbsp;" class="mybutton" />
                    <input type="button" onclick="del(); return false;" value="&nbsp;&nbsp;删&nbsp;除&nbsp;&nbsp;" class="mybutton" />
                    <input type="button" onclick="publish(); return false;" value="&nbsp;&nbsp;发&nbsp;布&nbsp;&nbsp;" class="mybutton" />
                </td>
            </tr>
        </table>
    </div>
    <input type="hidden" name="checkbox_app" id="checkbox_app" value="" />
    <table id="listtable"></table>
    <div class="buttondiv"></div>
</form>

<script type="text/javascript">
    var appid = '@ViewData["appId"]';
    var iframeid = '@ViewData["tabId"]';
    var typeid = '@ViewData["typeId"]';
    var dialog = top.mainDialog || new RoadUI.Window();
    var curPageSize;
    var curPageNumber;
    $(function () {
        $("#listtable").jqGrid({
            url: "Query?@Html.Raw(ViewData["query"])",
            mtype: 'POST',
            datatype: "json",
            colNames: ['应用名称', '分类', '创建时间','创建人', '状态', '操作'],
            colModel: [
                { name: 'Name', index: 'Name'},
                { name: 'Type', index: 'Type', align: "left"},
                { name: 'CreateTime', index: 'CreateTime', align: "left" },
                { name: 'CreateUserId', index: 'CreateUserId', align: "left" },
                { name: 'Status', index: 'Status', align: "left"},
                { name: 'Opation', index: '', sortable: false, align: "left", width: 60}
            ],
            sortname: "CreateTime",
            sortorder: "desc",
            height: '100%',
            multiselect: true,
            width: $(window).width(),
            loadComplete: function () {
                var gridObj = $("#listtable");
                var records = gridObj.getGridParam("userData");
                curPageSize = records.pagesize;
                curPageNumber = records.pagenumber;
                $(".buttondiv").html(RoadUI.Core.getPager1(records.total, records.pagesize, records.pagenumber, "query"));
            }
        });
    });

    $(window).resize(function () {
        $("#listtable").setGridWidth($(window).width());
    });

    function query(size, number) {
        var data = {
            Name: $("#Name").val(), pagesize: size || curPageSize, pagenumber: number || curPageNumber
        };
        $("#listtable").setGridParam({postData: data}).trigger("reloadGrid");
    }

    function edit(id) {
        var url = 'Edit?programid=' + id + '&pagesize=' + curPageSize + "&pagenumber=" + curPageNumber + '&@Html.Raw(ViewData["query"])';
        window.location = url;
    }

    function del() {
        var rowIds = $("#listtable").jqGrid('getGridParam', 'selarrrow');
        if (rowIds.length === 0) {
            alert("您没有选择要删除的项!");
            return false;
        }
        if (!confirm('您真的要删除所选应用吗?')) {
            return false;
        }
        $.ajax({
            url: "Delete?" + "@Html.Raw(ViewData["query"])" + "&pagesize=" + curPageSize + "&pagenumber=" + curPageNumber,
            data: { "ids": rowIds.join(","), "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val() },
            type: "post",
            success: function (txt) {
                alert(txt);
                query(curPageSize, curPageNumber);
            }
        });
        return true;
    }
</script>
